﻿<template>
<div>
  <el-dialog
    :title="!dataForm.unitCode ? $t('handle.add') :  btnshow ? '修改':'详情'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="150px">
    <el-form-item label="单位名称" prop="name">
      <el-input v-model="dataForm.name" :disabled="isInput" placeholder="单位名称"></el-input>
    </el-form-item>
        <el-row>
        <el-col :span="12">
          <el-form-item label="所属房屋"  prop="houseName">
            <el-input :disabled="true" v-model="houseAndUnit.houseName" placeholder="实有房屋" style="width:78%"></el-input><el-button type="info" plain :disabled="isInput"  @click="buttonHouseHandle()">选择</el-button>
          </el-form-item>
        </el-col>
          <el-col :span="12">
            <el-form-item label="房屋关系"  prop="type">
              <el-select v-model="houseAndUnit.type" :disabled="isInput" placeholder="请选择" style="width:100%">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
            </el-select>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="单位属性" prop="dwsxValue">
      <el-select v-model="dataForm.dwsxValue" :disabled="isInput" placeholder="请选择" style="width:100%">
        <el-option
          v-for="item in dwsxOptions"
          :key="item.id"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位类别" prop="qylbValue">
      <el-select v-model="dataForm.qylbValue" :disabled="isInput" placeholder="请选择" style="width:100%">
        <el-option
          v-for="item in qylbOptions"
          :key="item.id"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="统一社会编码" prop="businessLicense">
      <el-input v-model="dataForm.businessLicense" :disabled="isInput" placeholder="营业执照号"></el-input>
    </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="注册类型" prop="qyczlxValue">
      <el-select v-model="dataForm.qyczlxValue" placeholder="请选择" :disabled="isInput" style="width:100%">
        <el-option
          v-for="item in qyczlxOptions"
          :key="item.id"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
<el-form-item label="控股情况" prop="kgqkValue">
      <el-select v-model="dataForm.kgqkValue" :disabled="isInput" placeholder="请选择" style="width:100%">
        <el-option
          v-for="item in kgqkOptions"
          :key="item.id"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
        </el-col>
        <el-col :span="12">
           <el-form-item label="经营范围" prop="jyfwValue">
      <el-select v-model="dataForm.jyfwValue" :disabled="isInput" placeholder="请选择" style="width:100%">
        <el-option
          v-for="item in jyfwOptions"
          :key="item.id"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
<el-form-item label="是否有监控" prop="monitoringValue">
      <el-select v-model="dataForm.monitoringValue" :disabled="isInput" placeholder="请选择" style="width:100%">
        <el-option
          v-for="item in monitoringOptions"
          :key="item.id"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
        </el-col>
        <el-col :span="12">
             <!-- <el-form-item label="标准地址" prop="regionId">
      <el-input v-model="dataForm.regionId" placeholder="标准地址" :disabled="true" style="width:79%"></el-input><el-button type="info" plain @click="peoplebuttonHandle()">选择</el-button>
    </el-form-item> -->
        </el-col>
      </el-row>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('handle.cancel') }}</el-button>
      <el-button type="primary" v-show="btnshow" @click="dataFormSubmit()">{{ $t('handle.confirm') }}</el-button>
    </span>
  </el-dialog>
    <!-- <address-Dialog v-if="addressVisible" ref="addressDialog" @receiveParameters="getAddressParameters"></address-Dialog> -->
    <house-Dialog v-if="houseVisible" ref="houseDialog" @receiveParameters="getHouseParameters"></house-Dialog>
</div>
</template>

<script>
  import { getDictList } from '@/utils'
  import HouseDialog from '../dialog/houseDialogMore'
  // import AddressDialog from '../addressDialog'
  export default {
    data () {
      return {
        visible: false,
        isInput: false,
        dataForm: {
          unitCode: '',
          name: '',
          dwsxValue: '', // 单位属性选中项
          qyczlxValue: '', // 单位注册类型选中项
          qylbValue: '', // 单位类别
          kgqkValue: '', // 控股情况数据
          jyfwValue: '',  // 经营范围选中项
          monitoringValue: '', // 是否有监控选中项
          businessLicense: '',
          type: '',
          houseName: '',
          btnshow: true
        },
        houseAndUnit: {
          houseId: '',
          houseName: '',
          type:'',
          relationId:''
        },
        houseVisible: false,
        dataRule: {
          name: [
            { required: true, message: '单位名称不能为空', trigger: 'blur' }
          ],
          dwsxValue: [
            { required: true, message: '单位属性不能为空', trigger: 'blur' }
          ],
          qylbValue: [
            { required: true, message: '单位类别不能为空', trigger: 'blur' }
          ],
          qyczlxValue: [
            { required: true, message: '单位注册类型不能为空', trigger: 'blur' }
          ],
          kgqkValue: [
            { required: true, message: '控股情况不能为空', trigger: 'blur' }
          ],
          jyfwValue: [
            { required: true, message: '经营范围不能为空', trigger: 'blur' }
          ],
          monitoringValue: [
            { required: true, message: '是否有监控不能为空', trigger: 'blur' }
          ],
          houseName: [
            { required: true, message: '房屋不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '人房关系不能为空', trigger: 'blur' }
          ],
          businessLicense: [
            { required: true, message: '营业执照号不能为空', trigger: 'blur' }
          ]
        },
        dwsxOptions: [], // 单位属性数据
        qylbOptions: [], // 单位类别数据
        qyczlxOptions: [], // 单位注册类型数据
        kgqkOptions: [], // 控股情况数据
        jyfwOptions: [], // 经营范围数据
        options: [],
        btnshow: true,
        addressVisible: false,
        monitoringOptions: [] // 是否有监控数据
      }
    },
    computed: {
      regionId() {
        return this.$store.state.address.id;
      }
    },
    // components: {
    //   'address-Dialog': AddressDialog
    // },
    components: {
      'house-Dialog': HouseDialog
    },
    methods: {
      init (id,detail) {
        this.getSelectData()
        this.initFrom(id, detail)
      },
      getHouseParameters (data) {
        this.houseAndUnit.houseId = data.selectId
        this.houseAndUnit.houseName = data.selectText
        this.dataForm.houseName = data.selectText
      },
      initFrom (id, detail) {
        this.btnshow = true
        this.dataForm.unitCode = id || 0
        this.visible = true
        this.isInput = false
        if (detail) {
          this.btnshow = false
          this.isInput = true
        }
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.unitCode) {
            this.$http({
              // url: this.$http.adornUrl(`/dgactualunit/info/${this.dataForm.unitCode}`),
              url: `/dg-standard-info/dgactualunit/info/${this.dataForm.unitCode}`,
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.dgActualUnit.name
                this.dataForm.dwsxValue = data.dgActualUnit.institutions
                this.dataForm.qylbValue = data.dgActualUnit.businessCategory
                this.dataForm.qyczlxValue = data.dgActualUnit.typeBusiness
                this.dataForm.kgqkValue = data.dgActualUnit.holdings
                this.dataForm.jyfwValue = data.dgActualUnit.businessScope
                this.dataForm.monitoringValue = data.dgActualUnit.monitoring
                this.dataForm.businessLicense = data.dgActualUnit.businessLicense

                this.houseAndUnit.houseId = data.dgActualUnit.addressVo.houseId
                this.houseAndUnit.houseName = data.dgActualUnit.addressVo.addressName
                this.houseAndUnit.type = data.dgActualUnit.addressVo.dictValue
                this.houseAndUnit.relationId = data.dgActualUnit.addressVo.relationId
              }
            })
          }
        })
      },
      buttonHouseHandle () {
        this.houseVisible = true
        this.$nextTick(() => {
          this.$refs.houseDialog.init()
        })
      },
      // getAddressParameters ( data ) {
      //   this.dataForm.regionId = data.selectId
      //   this.dataForm.addressText = data.selectText
      // },
      // addressDialogOpen () {
      //   this.addressVisible = true
      //   this.$nextTick(() => {
      //     this.$refs.addressDialog.init()
      //   })
      // },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.houseAndUnit.type = this.dataForm.type
            this.$http({
              // url: this.$http.adornUrl(`/dgactualunit/${!this.dataForm.unitCode ? 'save' : 'update'}`),
              url: `/dg-standard-info/dgactualunit/${!this.dataForm.unitCode ? 'save' : 'update'}`,
              method: 'post',
              data: this.$http.adornData({
                'unitCode': this.dataForm.unitCode || undefined,
                'name': this.dataForm.name,
                'institutions': this.dataForm.dwsxValue,
                'businessCategory': this.dataForm.qylbValue,
                'typeBusiness': this.dataForm.qyczlxValue,
                'holdings': this.dataForm.kgqkValue,
                'businessScope': this.dataForm.jyfwValue,
                'monitoring': this.dataForm.monitoringValue,
                'houseAndUnit': this.houseAndUnit,
                'businessLicense': this.dataForm.businessLicense,
                'sysCreateBy': this.$store.state.user.id,
                'sysUpdateBy': this.$store.state.user.id
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      getSelectData () {
        getDictList('business_category').then(({data}) => {
          this.qylbOptions = data.dictList
        })
        getDictList('institutions').then(({data}) => {
          this.dwsxOptions = data.dictList
        })
        getDictList('type_business').then(({data}) => {
          this.qyczlxOptions = data.dictList
        })
        getDictList('holdings').then(({data}) => {
          this.kgqkOptions = data.dictList
        })
        getDictList('business_scope').then(({data}) => {
          this.jyfwOptions = data.dictList
        })
        getDictList('monitoring').then(({data}) => {
          this.monitoringOptions = data.dictList
        })
        getDictList('type').then(({data}) => {
          if (data && data.code === 0) {
            this.options = data.dictList
          }
        })
      }
    }
  }
</script>

<style>
/* .custom-3E8EF7 .el-form-item.is-required .el-form-item__label:before {
    font-size: 22px;
}
.custom-3E8EF7 .el-input.is-disabled .el-input__inner {
  color: #00000088;
} */
</style>

